{%  extends "list/base.html" %}

{% block content %}

    <h3 style="text-align: center">出版社信息列表</h3>

    <form class="form-inline" method="post" action="/presssearch/">
      <div class="form-group">
        <label class="sr-only" for="pressname"></label>
        <input type="text" class="form-control" value="{{ pressname }}" id="pressname" name="pressname" placeholder="出版社名称">
      </div>
      <button type="submit" class="btn btn-default">搜索</button>
    </form>

    <table border="1" class="table table-bordered table-hover">
        <tr class="success">
            <th>编号</th>
            <th>出版社名称</th>
            <th>出版社地址</th>
            <th>操作</th>
        </tr>

        {% for press in presslist %}
            <tr>
                <td>{{ forloop.counter }}</td>
                <td>{{ press.pressname }}</td>
                <td>{{ press.pressaddress }}</td>
                <td>
                    <a class="btn btn-info glyphicon glyphicon-pencil btn-sm" href="/pressupdate/?id={{ press.id }}">修改</a>&nbsp;
                    {% comment %}<a class="btn btn-danger glyphicon glyphicon-trash btn-sm" href="/pressdelete/?id={{ press.id }}" onclick="return confirm('您确定删除吗？')">删除</a>{% endcomment %}
                    <a class="btn btn-danger glyphicon glyphicon-trash btn-sm" href="#" data-id="{{ press.id }}" data-toggle="modal" data-target="#myModal">删除</a>
                </td>
            </tr>
        {% endfor %}

        <tr>
            <td colspan="8" align="center"><a class="btn btn-primary glyphicon glyphicon-plus" href="/pressadd">添加出版社</a></td>
        </tr>
    </table>

    <!-- 模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="myModalLabel">信思智学提醒您</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        删除后不可恢复，确定删除吗？
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" id="sub">保存更改</button>
      </div>
    </div>
  </div>
</div>
<script>
    $(function () {
        $('#myModal').on('show.bs.modal', function (event) {
            // 获取触发模态框的按钮
            var button = $(event.relatedTarget); // Button that triggered the modal
            // 获取 data-id 属性值
            var dataId = button.data('id'); // Extract info from data-* attributes
            // 你可以在这里使用 dataId
            $("#sub").click(function () {
                window.location.href = "/pressdelete/?id="+dataId
            });
        });
    })
</script>

{% endblock %}